<?php
$this_file = str_replace( '\\', '/', __FILE__ );
$this_file = explode( 'wp-content', $this_file );
$this_file = $this_file[ 0 ];

// required for making tables easier
require_once( $this_file . 'wp-config.php' );

global $wpdb;

function ue_check_column($table_name, $col_name, $col_type, $is_null = null, $key = null, $default = null, $extra = null) {
	global $wpdb;
	$diffs = 0;
	$results = $wpdb->get_results("DESC $table_name");

	foreach ($results as $row ) {

		if ($row->Field == $col_name) {
			// got our column, check the params
			if (($col_type != null) && ($row->Type != $col_type)) {
				++$diffs;
			}
			if (($is_null != null) && ($row->Null != $is_null)) {
				++$diffs;
			}
			if (($key != null) && ($row->Key  != $key)) {
				++$diffs;
			}
			if (($default != null) && ($row->Default != $default)) {
				++$diffs;
			}
			if (($extra != null) && ($row->Extra != $extra)) {
				++$diffs;
			}
			if ($diffs > 0) {
				return false;
			}
			return true;
		} // end if found our column
	}
	return false;
}

// extend wp_posts table
if( !ue_check_column( $wpdb->posts, 'vote_up', 'varchar(20)' ) ) {
	$zdm = "ALTER TABLE $wpdb->posts ADD vote_up varchar(20) NOT NULL DEFAULT '0'";
	$wpdb->query( $zdm );
} 
if( !ue_check_column( $wpdb->posts, 'vote_down', 'varchar(20)' ) ) {
	$bzdm = "ALTER TABLE $wpdb->posts ADD vote_down varchar(20) NOT NULL DEFAULT '0'";
	$wpdb->query( $bzdm );
} 

if( !ue_check_column( $wpdb->posts, 'faves', 'varchar(20)' ) ) {
	$faves = "ALTER TABLE $wpdb->posts ADD faves varchar(20) NOT NULL DEFAULT '0'";
	$wpdb->query( $faves );
}
if( !ue_check_column( $wpdb->users, 'user_faves', 'text' ) ) {
	$user_faves = "ALTER TABLE $wpdb->users ADD user_faves text";
	$wpdb->query( $user_faves );
} 

?>